# 可以理解为结构体, 实现几个rule之间的内容交互
Info = provider()

# 常见一个啥也不是的规则
def _impl(ctx):
    print(ctx)   #  <rule context for //printer:printer>

    # ["actions", "aspect_ids", "attr", "bin_dir", "build_file_path", 
    # "build_setting_value", "check_placeholders", "configuration", 
    # "coverage_instrumented", "created_actions", "default_provider", 
    # "disabled_features", "exec_groups", "executable", "expand_location", 
    # "expand_make_variables", "features", "file", "files", "fragments", 
    # "genfiles_dir", "host_configuration", "host_fragments", "info_file", 
    # "label", "new_file", "outputs", "resolve_command", "resolve_tools", 
    # "rule", "runfiles", "split_attr", "target_platform_has_constraint", 
    # "tokenize", "toolchains", "var", "version_file", "workspace_name"]
    # print(dir(ctx))

    # Target //printer:printer
    print("Target {} : attr number {}".format(ctx.label, ctx.attr.number)) 
    return [Info(number = ctx.attr.number)]


printer = rule(
    implementation = _impl,
    attrs = {
        # 传递参数信息
        "number" : attr.int(default = 1),
    },
)


def _impl_with_label(ctx):
    print(ctx.attr.label)
    print(type(ctx.attr.label))    # Target 类型
    print("number: ", ctx.attr.label[Info])
    print("number: ", ctx.attr.label[Info].number)


printer_with_label = rule(
    implementation = _impl_with_label,
    attrs = {
        "label" : attr.label(),
    },
)